﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using JTicket.BLL;

namespace JTicket.UI
{
    public partial class JT_ReturnManager : RoleBase
    {
        private readonly BLL.D_OperInfo bllOper = new BLL.D_OperInfo();
        protected void Page_Load(object sender, EventArgs e)
        {

            //if (!IsPostBack)
                Bind();
        }

        protected void dg1_ItemDataBound(object sender, DataGridItemEventArgs e)
        {
            if (e.Item.ItemIndex == -1) return;
            e.Item.Attributes.Add("bgcolor", "#EFFFDA");
            e.Item.Attributes.Add("style", "cursor:hand");
            e.Item.Attributes.Add("onMouseOver=this.style.backgroundColor", "#DBE3FA");
            e.Item.Attributes.Add("onMouseOut=this.style.backgroundColor", "#F6F6F6");

        }
        void Bind()
        {
            int status = 1;
            if (!string.IsNullOrEmpty(Request.QueryString["S"]))
            {
                status = Convert.ToInt32(Request.QueryString["S"].ToString());
            }
                Model.D_OperInfo oper = bllOper.Oper();
                List<Model.H_Return> model = new List<Model.H_Return>();
                string CurLevel = oper.CurLevel.ToString();//系统级权限
                string ThCode = oper.ThCode;//企业编号
                switch (CurLevel)
                {
                    case "0":
                        model = DAL.H_Return.GetLists(status);
                        this.dg1.DataSource = model;
                        this.dg1.DataBind();
                        break;
                    case "3":
                        model = DAL.H_Return.GetListT(ThCode, status);
                        this.dg1.DataSource = model;
                        this.dg1.DataBind();
                        break;
                }
        }
        public string state(string st)
        {
            switch (st)
            {
                case "1":
                    return "审核中";
                case "2":
                    return "已审核通过";
                default:
                    return "未审核中";
            }
        }
        protected void ImageButton1_Command(object sender, EventArgs e)
        {
            string BarCode = dg1.Items[0].Cells[0].Text;
            string TitleCode = dg1.Items[0].Cells[1].Text;
            if (!DAL.H_Return.GetStatus(BarCode, TitleCode))
            {

                string Area = dg1.Items[0].Cells[4].Text;
                string Row = dg1.Items[0].Cells[6].Text;
                string Cow = dg1.Items[0].Cells[7].Text;
                string Note = dg1.Items[0].Cells[5].Text;
                string sixid = dg1.Items[0].Cells[8].Text;
                string TicketName = dg1.Items[0].Cells[9].Text;
                string OperCode = bllOper.Oper().OperCode;
                string Model = "退票审核";
                bool b = false;
                b = DAL.H_TicketBal.ReturnTicket
                       (BarCode, TitleCode, Area, Row, Cow, Note, TicketName, OperCode, Model);
                if (b)
                {
                    Common.JsMsg.MsgBoxRedrect("退票审核通过操作成功!", "JT_ReturnManager.aspx", this.Page);
                    Bind();
                }
                else
                    Common.JsMsg.Alert("退票审核失败，请重新操作！");
            }
            else
                Common.JsMsg.Alert("此票已审核通过。。。！");
        }
    }
}